import http from '@/utils/http/axios';
import {ContentTypeEnum} from "@/enums/httpEnum";
import {
  LoginParams,
  LoginResultModel,
  GetUserInfoByUserIdParams,
  GetUserInfoByUserIdModel,
} from './model/userModel';

enum Api {
  login = '/mall-admin/admin/login',
  logout = '/mall-admin/admin/logout',
  info = '/mall-admin/admin/info'
}

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
  return http.request({
    url: Api.info,
    method: 'GET',
  }, {
    isTransformRequestResult: false
  });
}

/**
 * @description: 用户登录
 */
export function login(params: LoginParams) {
  console.log('params', params)
  return http.request({
    url: Api.login,
    method: 'POST',
    headers: {
      'Content-type': ContentTypeEnum.JSON
    },
    params,
  }, {
    isTransformRequestResult: false,
    isParseToJson: true
  });
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params, uid) {
  return http.request({
    url: `/user/u${uid}/changepw`,
    method: 'POST',
    params,
  }, {
    isTransformRequestResult: false
  });
}

/**
 * @description: 用户登出
 */
export function logout(params) {
  return http.request({
    url: Api.logout,
    method: 'POST',
    params,
  });
}
